<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Github用户搜索</h3>
    <div>
      <input
        type="text"
        placeholder="请输入要搜索的用户名"
        v-model="keyword"
      />&nbsp;<button @click="search">搜索</button>
    </div>
  </section>
</template>

<script>
import axios from "axios";

export default {
  name: "Search",
  data() {
    return {
      keyword: "",
    };
  },
  methods: {
    search() {
      axios.get(`https://api.github.com/search/users?q=${this.keyword}`).then(
        (response) => {
          this.$bus.$emit('user-list',response.data.items)
        },
        (error) => {
          console.log("失败了", error.message);
        }
      );
    },
  },
};
</script>